﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using A2DFramework.AOPService.Core;
using A2DFramework.SQLDispatcherService.Context;
using A2DFramework.AOPService;
using A2DFramework.SQLDispatcherService.SimpleADOdotNetDispatcher;

namespace A2DFramework.SQLDispatcherService.ConcreteAOPProcessor
{
    class SQLDispatcherAOPProcessor : IAOPProcessor
    {
        public AOPService.FollowAction PreProcess(System.Runtime.Remoting.Messaging.IMessage requestMsg)
        {
            bool tagExist = true;
            SQLDispatcherAttribute attr = AOPHelper.CheckDefinationTag<SQLDispatcherAttribute>(requestMsg, ref tagExist);
            if (!tagExist)
                attr = new SQLDispatcherAttribute(string.Empty);

            SQLDispatcherContext ctx = new SQLDispatcherContext();
            ctx.Region = attr.Region;
            SQLDispatcherContext.SetCurrentContext(ctx);

            return new FollowAction(true);
        }

        public void PostProcess(System.Runtime.Remoting.Messaging.IMessage requestMsg, System.Runtime.Remoting.Messaging.IMessage responseMsg)
        {
            SQLDispatcherContext.ResetCurrentContext();
        }
    }
}
